package com.google.code.qsecurity.client.event;

import java.util.Date;

import com.google.code.qsecurity.shared.proxy.UserProxy;

public class OnlineEvent extends StateChangeEvent {
	
	private String sessionId;
	private Date expiration;

	/**
	 * Handler type.
	 */
	private static Type<StateChangeHandler> TYPE;
	
	/**
	 * Creates a new open event.
	 * 
	 * @param target the user signing online
	 */
	public OnlineEvent(UserProxy user, String sessionId, Date expiration) {
		super(user);
		this.sessionId = sessionId;
		this.expiration = expiration;
	}

	/**
	 * Gets the type associated with this event.
	 * 
	 * @return returns the handler type
	 */
	public static Type<StateChangeHandler> getType() {
		if (TYPE == null) {
			TYPE = new Type<StateChangeHandler>();
		}
		return TYPE;
	}

	@Override
	public final com.google.gwt.event.shared.GwtEvent.Type<StateChangeHandler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch(StateChangeHandler handler) {
		handler.onStateChange(this);
	}

	public String getSessionId() {
		return sessionId;
	}

	public Date getExpiration() {
		return expiration;
	}

}
